/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.account.Key.AccountBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.SoapFaultException;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.AccountServiceException;
/*    */ import com.zimbra.cs.account.AttributeClass;
/*    */ import com.zimbra.cs.account.DataSource;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*    */ import com.zimbra.cs.service.account.ToXML;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import com.zimbra.soap.admin.type.DataSourceType;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class CreateDataSource
/*    */   extends AdminDocumentHandler
/*    */ {
/* 40 */   private static final String[] TARGET_ACCOUNT_PATH = { "id" };
/* 41 */   protected String[] getProxiedAccountPath() { return TARGET_ACCOUNT_PATH; }
/*    */   
/*    */ 
/*    */ 
/*    */   public boolean domainAuthSufficient(Map context)
/*    */   {
/* 47 */     return true;
/*    */   }
/*    */   
/*    */   public Element handle(Element request, Map<String, Object> context) throws ServiceException, SoapFaultException {
/* 51 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 52 */     Provisioning prov = Provisioning.getInstance();
/*    */     
/* 54 */     String id = request.getAttribute("id");
/*    */     
/* 56 */     Account account = prov.get(Key.AccountBy.id, id, zsc.getAuthToken());
/* 57 */     if (account == null) {
/* 58 */       throw AccountServiceException.NO_SUCH_ACCOUNT(id);
/*    */     }
/* 60 */     checkAdminLoginAsRight(zsc, prov, account);
/*    */     
/* 62 */     Element dsEl = request.getElement("dataSource");
/* 63 */     Map<String, Object> attrs = AdminService.getAttrs(dsEl);
/*    */     
/* 65 */     DataSourceType type = DataSourceType.fromString(dsEl.getAttribute("type"));
/*    */     
/*    */ 
/* 68 */     if (isDomainAdminOnly(zsc))
/*    */     {
/*    */ 
/* 71 */       AttributeClass klass = ModifyDataSource.getAttributeClassFromType(type);
/* 72 */       checkModifyAttrs(zsc, klass, attrs);
/*    */     }
/*    */     
/* 75 */     String name = dsEl.getAttribute("name");
/*    */     
/* 77 */     DataSource ds = Provisioning.getInstance().createDataSource(account, type, name, attrs);
/* 78 */     Element response = zsc.createElement(AdminConstants.CREATE_DATA_SOURCE_RESPONSE);
/* 79 */     ToXML.encodeDataSource(response, ds);
/* 80 */     return response;
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 85 */     relatedRights.add(Rights.Admin.R_adminLoginAs);
/* 86 */     relatedRights.add(Rights.Admin.R_adminLoginCalendarResourceAs);
/* 87 */     notes.add("If the target is an account, need the adminLoginAs right; If the target is a calendar resource, need the R_adminLoginCalendarResourceAs right.");
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/CreateDataSource.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */